from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from try_mysql import *
from PyQt5.uic import loadUiType
import begin_py
from movie_record_manage_ui import Ui_Movie_record
import sys
ui, _ = loadUiType('register.ui')

class Register_App(QMainWindow, ui):
    #定义构造
    def __init__(self):
        QMainWindow.__init__(self)
        self.setupUi(self)
        #self.handle_ui_change()
        self.handle_buttons()
        self.handle_buttons()
        self.registe_password.setEchoMode(QLineEdit.Password)
        self.confirm_regist_password.setEchoMode(QLineEdit.Password)
        self.show()

    def handle_buttons(self):
        self.new_staff_register.clicked.connect(self.New_staff_register)
        self.cancel_staff_register.clicked.connect(self.Close)

    def New_staff_register(self):
        conn = get_conn()
        cur = conn.cursor()
        StaffName = self.staff_name.text()
        StaffNum = self.registe_staff_num.text()
        StaffPassword = self.registe_password.text()
        StaffPass=self.confirm_regist_password.text()
        if (StaffName =="" or StaffNum=="" or StaffPassword=="" or StaffPass==""):
            self.statusBar().showMessage('字段为空添加有毛用！')
            return
        if(StaffPassword!=StaffPass):
            self.statusBar().showMessage('密码不一致哟！')
            return
        else:
            sql = "insert into user(StaffName,StaffNum,StaffPassword) VALUES (%s,%s,%s)"
            values = (StaffName, StaffNum, StaffPassword)
            cur.execute(sql, values)
            conn.commit()
            close_conn(conn, cur)
            print(QMessageBox.information(self, "提醒", "注册成功", QMessageBox.Yes, QMessageBox.Yes))
            self.Back = begin_py.Begin_App()
            self.close()
            self.Back.show()
        return

    def Close(self):
        self.Back = begin_py.Begin_App()
        self.close()
        self.Back.show()


    def clearEdit(self):
        self.staff_name.clear()
        self.registe_staff_num.clear()
        self.registe_password.clear()



def main():
    app = QApplication([])
    window = Register_App()
    window.show()
    app.exec_()

if __name__ == '__main__':
    main()